package com.ruoyi.consumer.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.consumer.domain.COrder;
import com.ruoyi.consumer.service.impl.COrderServiceImpl;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.consumer.domain.COrderInvoice;
import com.ruoyi.consumer.service.ICOrderInvoiceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 发票Controller
 * 
 * @author lizhouwei
 * @date 2023-11-14
 */
@RestController
@RequestMapping("/consumer/invoice")
public class COrderInvoiceController extends BaseController
{
    @Autowired
    private ICOrderInvoiceService cOrderInvoiceService;

    @Autowired
    private COrderServiceImpl orderService;
    /**
     * 查询发票列表
     */
    @PreAuthorize("@ss.hasPermi('consumer:invoice:list')")
    @GetMapping("/list")
    public TableDataInfo list(COrderInvoice cOrderInvoice)
    {
        startPage();
        return getDataTable(cOrderInvoiceService.selectCOrderInvoiceList(cOrderInvoice));
    }

    /**
     * 导出发票列表
     */
    @PreAuthorize("@ss.hasAnyRoles('common,admin,dragon')")
    @Log(title = "发票", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, COrderInvoice cOrderInvoice)
    {
        List<COrderInvoice> list = cOrderInvoiceService.selectCOrderInvoiceList(cOrderInvoice);
        ExcelUtil<COrderInvoice> util = new ExcelUtil<COrderInvoice>(COrderInvoice.class);
        util.exportExcel(response, list, "发票数据");
    }

    /**
     * 获取发票详细信息
     */
    @PreAuthorize("@ss.hasAnyRoles('common,admin,dragon')")
    @GetMapping(value = "/{invoiceId}")
    public AjaxResult getInfo(@PathVariable("invoiceId") Integer invoiceId)
    {
        return success(cOrderInvoiceService.selectCOrderInvoiceByInvoiceId(invoiceId));
    }

    /**
     * 新增发票
     */
    @PreAuthorize("@ss.hasPermi('consumer:invoice:add')")
    @Log(title = "发票", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody COrderInvoice cOrderInvoice)
    {
        return toAjax(cOrderInvoiceService.insertCOrderInvoice(cOrderInvoice));
    }

    /**
     * 修改发票
     */
    @Log(title = "发票", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody COrderInvoice cOrderInvoice)
    {
        return toAjax(cOrderInvoiceService.updateCOrderInvoice(cOrderInvoice));
    }

    /**
     * 删除发票
     */
    @PreAuthorize("@ss.hasAnyRoles('common,admin,dragon')")
    @Log(title = "发票", businessType = BusinessType.DELETE)
	@DeleteMapping("/{invoiceIds}")
    public AjaxResult remove(@PathVariable Integer[] invoiceIds)
    {
        return toAjax(cOrderInvoiceService.deleteCOrderInvoiceByInvoiceIds(invoiceIds));
    }
}
